<?php

namespace App\Models\System;

use App\Traits\ModelTrait;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Foundation\Auth\User as Authenticates;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticates
{
    use HasApiTokens, HasRoles, ModelTrait;
    protected $table = 'users';
    protected $fillable = [
        'username',
        'email',
        'mobile',
        'avatar',
        'display_name',
        'password',
        'sex',
        'describe',
        'status',
        'remember_token',
        'uuid',
        'last_login_ip',
        'last_login_time'
    ];
    protected $hidden = ['password', 'remember_token'];

    public function first($columns = ['*'])
    {
        cache()->put('aaa', 1, 1000);
        return $this->take(1)->get($columns)->first();
    }

    public function find($id, $columns = ['*'])
    {
        cache()->put('aaa', 1, 1000);
        if (is_array($id) || $id instanceof Arrayable) {
            return $this->findMany($id, $columns);
        }

        return $this->whereKey($id)->first($columns);
    }
}
